<template>
  <div id="list-container">
    <ul class="list">
      <li
        v-for="(item, index) in listData"
        :key="index"
        class="list-item"
        @click="listClick(index)"
      >
        <img :src="item.imageurl" alt="" />
        <div class="right">
          <h3 class="title">{{ item.eventname }}</h3>
          <p><span>时间：</span>{{ item.happenTime }}</p>
          <p><span>地点：</span>{{ item.address }}</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'list',
  props: {
    listData: {
      type: Array,
      required: true
    }
  },
  methods: {
    goTop () {
      const that = this
      const timer = setInterval(() => {
        const ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop =
          that.scrollTop + ispeed
        if (document.documentElement.scrollTop <= 10) {
          clearInterval(timer)
        }
      }, 16)
      document.documentElement.scrollTop = 0
      // window.scrollTo(0, 0)
    },
    listClick (index) {
      this.$emit('listClick', this.listData, index)
    }
  },
  updated () {
    this.goTop()
  }
}
</script>

<style>
.list-container {
  width: 100%;
}
.list {
  max-height: 1600px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  width: 100%;
}
.list .list-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  width: 798px;
  height: 208px;
  box-sizing: border-box;
  cursor: pointer;
}
.list .list-item img {
  width: 360px;
  height: 208px;
  border-radius: 8px;
}
.list .list-item .right {
  width: 424px;
  box-sizing: border-box;
}
.list .list-item > div>h3 {
  background: linear-gradient(to right,rgb(0, 40, 123),transparent);
  margin: 0;
  padding:16px 0 16px 16px;
  font-size: 36px;
}
.list .list-item > div > * {
  width: 420px;
  overflow: hidden; /*超出部分隐藏*/
  white-space: nowrap; /*不换行*/
  text-overflow: ellipsis; /*超出部分文字以...显示*/
}
.list .list-item > div > h3 {
  font-weight: inherit;
  margin-bottom: 16px;
}
.list .list-item > div > p > span {
  font-size: 32px;
  line-height: 60px;
  color: rgb(205, 204, 204);
}
</style>
